<?php


namespace app\model;

use think\Model;
use hg\apidoc\annotation\WithoutField;

class BaseModel extends Model
{
    protected $autoWriteTimestamp = true;
    protected $createTime = 'create_at';
    protected $updateTime = 'update_at';

    //根据查询条件获取当前模型的 分页列表
    public function getList($where = [], $page = 0, $limit = 20, $field = [], $order = ["id" => "desc"]): array
    {
        return $this->where($where)->order($order)->field($field)->paginate(['page' => $page, 'list_rows' => $limit])->toArray();
    }

    /**
     * @WithoutField("")
     */
    public function all(): array
    {
        return $this->select()->toArray();
    }

    /**
     * @withoutField("")
     */
    public function getInfoById($id)
    {
        return $this->where('id', $id)->find();
    }

    //新增一条数据
    public function createInfo($data)
    {
        return $this->create($data);
    }

    //按id 更新数据
    public function updateInfo($id, $data, $field = true): bool
    {
        $res = $this->where(["id" => $id])->field($field)->save($data);
        if ($res) {
            return true;
        } else {
            return false;
        }
    }
}